<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>微信登录</title>
    <!-- vue -->
    <script src="js/plugins/vue/dist/vue.js"></script>
    <!-- axios -->
    <script src="js/plugins/axios/dist/axios.js"></script>
    <!-- axios全局配置 -->
    <script src="js/common.js"></script>
</head>
<body>
<div id="myDiv"></div>
</body>
<script>
    new Vue({
        el: "#myDiv",
        mounted() {
            // http://bugtracker.itsource.cn/callback.html?code=091vWz100MW2hO12CG000WRrLN2vWz1E&state=1
            let url = location.href;
            let code = parseUrlParams2Obj(url).code;
            this.$http.get("/login/wechat/" + code).then(res => {
                if (res.data.success == true) {
                    alert("登录成功");
                    // 解构表达式，取出登录信息和令牌，将令牌和登录信息存入localStorage中，方便做登录拦截
                    let {logininfo, token} = res.data.resultObj;
                    localStorage.setItem("token", token);
                    localStorage.setItem("logininfo", JSON.stringify(logininfo));//拿到的是一个对象，需要转成json
                    location.href = "/index.html";
                } else {
                    let {access_token, openid} = res.data.resultObj;
                    location.href = "/binder.html?accessToken="+access_token+"&openId="+openid;
                }
            }).catch(res => {
                alert("系统错误, 稍后重试");
            })
        }
    });
</script>
</html>